﻿using System;
using System.Data;
using System.Data.OracleClient;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class CellAlarm_FocusM : UserPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CLASSAList.DataSource = GetTopUnlink("A类");
            CLASSAList.DataBind();
            CLASSBList.DataSource = GetTopUnlink("B类");
            CLASSBList.DataBind();
            CLASSCList.DataSource = GetTopUnlink("C类");
            CLASSCList.DataBind();
            Mtitle.InnerText = ConfigurationManager.AppSettings["SystemName"].Substring(0, 6);
            MFoot.InnerText = DateTime.Now.Year.ToString() + "©"
                + ConfigurationManager.AppSettings["CompanyName"] + "Gt";
        }
    }

    private DataSet GetTopUnlink(string argClass)
    {
        string sqlStr = @"SELECT * FROM (
                                    SELECT COUNTY,CELL_CHNAME,COUNT(1) AS COUNTS,'2G' AS NetType
                                      FROM AB_CELL_UNLINK T1   WHERE START_TIME > to_char(add_months(last_day(sysdate)+1,-1),'yyyy-MM-dd') 
                                        AND CELL_CLASS = '";
        sqlStr = sqlStr + argClass + @"' GROUP BY COUNTY,CELL_CHNAME UNION ALL
                                    SELECT SUBSTR(T2.CELL_CHNAME,0,2) AS COUNTY,CELL_CHNAME
                                           ,COUNT(1) AS Counts,'3G' AS NetType
                                      FROM ALARM_TABLE_3G T2  WHERE C_NUMBER = '7786'
                                       AND T2.CELL_CHNAME IS NOT NULL  AND T2.CELL_CLASS = '";
        sqlStr = sqlStr + argClass + @"' AND T2.STARTED>to_char(add_months(last_day(sysdate)+1,-1),'yyyy-MM-dd')
                                       AND (T2.CANCELED IS NULL OR TO_NUMBER((T2.CANCELED
                                          - T2.STARTED)*24*60) >= 1)
                                       AND (TO_NUMBER(TO_CHAR(T2.STARTED,'HH24'))>5
                                           OR (NVL(TO_NUMBER(TO_CHAR(T2.CANCELED,'HH24')),0)>5
                                           OR T2.CANCELED IS NULL))   
                                     GROUP BY SUBSTR(T2.CELL_CHNAME,0,2),CELL_CHNAME
                                     ORDER BY Counts DESC)  WHERE ROWNUM<=10";
        DataRow dr = GetOrganAndCompany().Rows[0];
        if ((!dr["company"].ToString().Equals("延安")) || dr["organ"].ToString().Equals("宝塔维护站"))
        {
            sqlStr = sqlStr + " AND COUNTY = '" + dr["company"].ToString() + "' ";
        }
        return OracleHelper.ExecuteDataSet(sqlStr, CommandType.Text, null);
    }
}
